const { CleanWebpackPlugin } = require('clean-webpack-plugin'); //打包前清空build目录文件
const ProgressBarPlugin = require('progress-bar-webpack-plugin'); // 打包进度条美化
const CopyWebpackPlugin = require('copy-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const path = require('path');
const chalk = require('chalk');

module.exports = require('./webpack.common')({
  mode: 'production',
  devtool: 'source-map',
  plugins: [
    new CleanWebpackPlugin(),
    new ProgressBarPlugin({
      format:
        `${chalk.green.bold('build[:bar]')} ` +
        chalk.green.bold(':percent') +
        ' (:elapsed seconds)',
      clear: false,
      width: 60,
    }),
    new HtmlWebpackPlugin({
      filename: 'index.html',
      title: 'vue-cli',
      url: './',
      template: './public/index.html',
    }),
    new CopyWebpackPlugin({
      patterns: [
        {
          from: path.join(__dirname, 'public'),
          globOptions: {
            ignore: [
              // 忽略html文件
              '**/*.html',
            ],
          },
        },
      ],
    }),
  ],
  stats: 'normal', //标准输出
});
